package kyu_5;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.LongStream;

public class IsMyFriendCheating {
    public static void main(String[] args) {
        removNb2(26) ;
    }

    public static List<long[]> removNb(long n) {
        // your code
        List<long[]> result = new ArrayList<long[]>(2) ;
        long sum = LongStream.rangeClosed(0, n).sum() ;
        long left = n / 2 ;
        long right = left+1 ;
        while(left>0 && right <n){
            long product = right*left ;
            long rediuce = sum - (right + left) ;
            if(rediuce == product){
                break ;
            }

            left-- ;
            right++ ;
        }

        result.add(new long[]{left,right});
        result.add(new long[]{right, left}) ;
        printRes(result);
        return result;
    }

    public static List<long[]> removNb2(long n) {
        // your code
        List<long[]> result = new ArrayList<long[]>(2) ;
        long sum = LongStream.rangeClosed(0, n).sum() ;
        for(long i=1; i<=n; i++){
            for(long j = i+1; j<=n; j++){
                long product = i * j ;
                long rediuce = sum - (i + j) ;
                if(product == rediuce){
                    result.add(new long[]{i,j});
                    result.add(new long[]{j, i}) ;
                    printRes(result);
                    return result ;
                }
            }
        }
        printRes(result);
        return result;
    }

    private static void printRes(List<long[]> res){
        for(long[] data : res){
            for(int i=0; i<data.length; i++)
                System.out.println(data[i]);
        }
    }
}
